package com.sxm.yiwei.pinche;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sxm.yiwei.R;
import com.sxm.yiwei.base.BaseActivity;
import com.sxm.yiwei.beans.pinche.Order;
import com.sxm.yiwei.constant.Common;
import com.sxm.yiwei.constant.Constant;
import com.sxm.yiwei.tools.CastTime;
import com.sxm.yiwei.utils.DateUtil;

public class OrderExceptionResultActivity extends BaseActivity {


    private RelativeLayout rl_back;
    private TextView tv_title;
    private TextView tv_start_pos;
    private TextView tv_end_pos;
    private TextView tv_order_code;
    private TextView tv_appeal_time;
    private TextView tv_handle_time;
    private TextView tv_result;
    private TextView tv_recent_time;
    private TextView tv_appeal_result;
    private ImageView img1;
    private ImageView img2;
    private ImageView img3;
    private Order order;
    private int identity;

    @Override
    public void setContentView() {
        setContentView(R.layout.activity_order_exception_result);
    }

    @Override
    public void initView() {
        rl_back = (RelativeLayout)findViewById(R.id.rl_back);
        tv_title = (TextView)findViewById(R.id.tv_title);
        tv_start_pos = (TextView)findViewById(R.id.tv_start_pos);
        tv_end_pos = (TextView)findViewById(R.id.tv_end_pos);
        tv_order_code = (TextView)findViewById(R.id.tv_order_code);
        tv_appeal_time = (TextView)findViewById(R.id.tv_appeal_time);
        tv_handle_time = (TextView)findViewById(R.id.tv_handle_time);
        tv_result = (TextView)findViewById(R.id.tv_result);
        tv_recent_time = (TextView)findViewById(R.id.tv_recent_time);
        tv_appeal_result = (TextView)findViewById(R.id.tv_appeal_result);
        img1 = (ImageView)findViewById(R.id.img1);
        img2 = (ImageView)findViewById(R.id.img2);
        img3 = (ImageView)findViewById(R.id.img3);
    }

    @Override
    public void initListener() {
        rl_back.setOnClickListener(this);
        img1.setOnClickListener(this);
        img2.setOnClickListener(this);
        img3.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.img1:
                break;
            case R.id.img2:
                break;
            case R.id.img3:
                break;
        }
    }

    @Override
    public void initData() {
        order = (Order) getIntent().getSerializableExtra("order");
        identity = getIntent().getIntExtra("identity",-1);
        tv_title.setText("订单异常处理结果");
        tv_start_pos.setText(order.getStart_place());
        tv_end_pos.setText(order.getEnd_place());
        tv_order_code.setText("订单号："+order.getOrder_code());

        getExceptionResult();
    }

    private void getExceptionResult() {
        JSONObject object = new JSONObject();
        object.put("orderId",order.getOrder_id());
        httpGet(Common.HOST+Common.EXCEPTION_RESULT,object, Constant.EXCEPTION_RESULT);
    }

    @Override
    public void onSuccess(String result, String fromWhere) {
        super.onSuccess(result, fromWhere);
        com.alibaba.fastjson.JSONObject obj = JSON.parseObject(result);
        JSONObject data = obj.getJSONObject("data");
        JSONObject complaint = data.getJSONObject("complaint");
        if (fromWhere.equals(Constant.EXCEPTION_RESULT)){
            showToast("获取成功");
            tv_recent_time.setText(CastTime.CastTime(complaint.getLong("complaintTime")));
            tv_appeal_time.setText("申诉时间："+DateUtil.times(complaint.getLong("complaintTime")));
            if (complaint.getString("result").equals("")){
                tv_result.setText("暂无回复，感谢您的耐心等待");
                tv_handle_time.setVisibility(View.GONE);
            }else {
                tv_result.setText(complaint.getString("result"));
                tv_handle_time.setVisibility(View.VISIBLE);
                tv_handle_time.setText(DateUtil.times(complaint.getLong("complaintHandleTime")));

            }
            tv_appeal_result.setText(complaint.getString("content"));

        }
    }
}
